<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
      class="globalSerchFormStyle"
    >
      <el-row>
        <el-col :span="6">
          <el-form-item label="卡号" prop="icCardno">
            <el-input
              v-model="queryParams.icCardno"
              placeholder="请输入卡号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
              style="width: 190px"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="卡类型" prop="cardType">
            <el-select
              v-model="queryParams.cardType"
              placeholder="请选择卡类型"
              clearable
              size="small"
              style="width: 190px"
            >
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="卡名称" prop="icCardname">
            <el-input
              v-model="queryParams.icCardname"
              placeholder="请输入卡名称"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
              style="width: 190px"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="联系人" prop="icContacts">
            <el-input
              v-model="queryParams.icContacts"
              placeholder="请输入联系人"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
              style="width: 190px"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-row class="global_el_rowStyle" :gutter="10">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          icon="el-icon-refresh"
          size="mini"
          @click="resetQuery"
          type="primary"
          plain
          >重置</el-button
        >
      </el-col>
    </el-row>
    <el-table
      v-loading="loading"
      :data="infoList"
      @selection-change="handleSelectionChange"
      stripe
    >
      <el-table-column type="selection" width="55" align="left" />

      <el-table-column
        label="卡类别"
        align="left"
        prop="cardType"
        :formatter="changecardTypeProp"
        sortable
      />
      <el-table-column label="卡号" align="left" prop="icCardno" sortable />
      <el-table-column
        label="手机号"
        align="left"
        prop="icContactsphone"
        sortable
      />
      <el-table-column label="联系人" align="left" prop="icContacts" sortable />
      <!-- <el-table-column label="注销原因" align="left" prop="cancellation" :show-overflow-tooltip="true"/> -->
      <!-- <el-table-column label="注销时间" align="left" prop="cancellationdate" /> -->
      <el-table-column label="卡名称" align="left" prop="icCardname" sortable />
      <el-table-column
        label="开卡时间"
        align="left"
        prop="createDate"
        width="180"
        sortable
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="充值总额" align="left" prop="totalrecharge" /> 
      <el-table-column label="余额" align="left" prop="amt" />  -->
      <!-- <el-table-column label="是否启用" align="left" prop="enable" /> -->
      <!-- <el-table-column label="免密支付" align="left" prop="issecret" :formatter="changeissecretProp" />
      <el-table-column label="操作" align="left" class-name="small-padding ">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-sugar"
            @click="handlePay(scope.row)"     
          >充值</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-unlock"
            @click="handleRestPasswd(scope.row)"
          >密码重置</el-button>
        </template>
      </el-table-column> -->
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  listInfo,
  updatepwd,
  statisticsInfo,
  updateRecharge,
  delInfo,
  exportInfo,
} from "@/api/ic/info";

export default {
  name: "Info",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 卡编号表格数据
      infoList: [],
      statistics: null,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      openPay: false,
      // 是否弹出充值密码
      openPasswd: false,
      options: [
        {
          value: "0",
          label: "通用",
        },
        {
          value: "1",
          label: "汽油",
        },
        {
          value: "2",
          label: "柴油",
        },
        {
          value: "3",
          label: "LNG",
        },
        {
          value: "4",
          label: "CNG",
        },
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        icCardno: null,
        icContactsphone: null,
        cardType: null,
        icCardname: null,
        createDate: null,
        icContacts: null,
        password: null,
        amt: null,
        enable: 1,
        issecret: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //改变显示的人物属性
    changecardTypeProp(row) {
      const manProp = row.cardType;
      var carTypeMsg = "通用";
      if (manProp == "1") {
        carTypeMsg = "汽油";
      } else if (manProp == "2") {
        carTypeMsg = "柴油";
      } else if (manProp == "3") {
        carTypeMsg = "LNG";
      } else if (manProp == "4") {
        carTypeMsg = "CNG";
      }
      return carTypeMsg;
    },
    changeissecretProp(row) {
      const manProp = row.issecret;
      var issecretMsg = "否";
      if (manProp == "1") {
        issecretMsg = "是";
      }
      return issecretMsg;
    },
    /** 查询卡编号列表 */
    getList() {
      this.getstatisticsInfo();
      this.loading = true;
      listInfo(this.queryParams).then((response) => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getstatisticsInfo() {
      statisticsInfo(this.queryParams).then((response) => {
        this.statistics = response.data;
      });
    },
    // 取消按钮
    cancel() {
      this.openPay = false;
      this.openPasswd = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        icCardno: null,
        icOldcardno: null,
        icContactsphone: null,
        cardType: null,
        icCardname: null,
        createDate: null,
        icContacts: null,
        password: null,
        amt: null,
        enable: null,
        issecret: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.icCardno);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
  },
};
</script>
